#import "@preview/frame-it:1.1.2": frames, frame-style, styles
#import "@preview/equate:0.3.1": equate

#let semantic_blocks = (
  notation: ("记法",),
  definition: ("定义",),
  axiom: ("公理",), 
  convention: ("惯例",),
  proposition: ("命题",), 
  lemma: ("引理",),
  theorem: ("定理",),
  corollary: ("推论",),
  proof: ("证明",),
  algorithm: ("算法",),
  example: ("示例",),
  exercise: ("习题",),
  solution: ("解答",),
  remark: ("注记",),
)

#let (theorem, proposition, lemma, corollary, algorithm) = frames(
  kind: "thesis", 
  ..semantic_blocks, 
)

#let (axiom, definition, notation, convention) = frames(
  kind: "concept",
  ..semantic_blocks,
)

#let (proof, solution) = frames(
  kind: "proofs",
  ..semantic_blocks,
)

#let (example, exercise, remark) = frames(
  kind: "examples", 
  ..semantic_blocks,
)

///////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////// 

#let ul = underline

// 一个自带标签的环境。采用某种特殊格式来附着标签，默认是加粗 emph。
// 可惜我们并不能把它的 func 硬调成 term, 
// 因为 emph 是元件函数, 而 Typst 脚本不制造元件函数。
#let term(body, func:emph) = {
  let prompt = body
  if type(body) != str {
    prompt = repr(body).slice(1, -1)
  }
  [#func(body)#label(prompt)]
}

#let forward(body, color: gray) = text(fill: color, body)

#let title(body, size:28pt) = align(center, text(size, strong(body)))

#let RoseLic(doc) = {
  // 设置字体
  // set text(
  //   font: (
  //   "libertinus serif",
  //   "lxgw wenkai gb"
  // ))
  // show math.equation: set text(font: (
  //   "New Computer Modern Math", 
  //   "STZhongSong",
  // ))
  show emph: set text(font: (
      "libertinus serif", 
      "STXinwei"
  ))
  show ref: it => {
    if it.element.func() in (strong, emph, raw) {
      return link(it.target, text(fill: navy, it.element.body))
    }
    it
  }

  // 设置段落、块体及标号
  set heading(numbering: "1.1.1.1")
  show: equate.with(breakable: true, sub-numbering: true, number-mode: "label")
  set math.equation(numbering: "(1.1)")
  show figure: set enum(numbering: "(1)")
  show: frame-style(styles.boxy)
  show figure.where(kind: table): set figure.caption(position: top)
  show figure.where(kind: "examples"): frame-style(styles.hint)
  show figure.where(kind: "proofs"): set block(breakable: true)
  show figure.where(kind: "proofs"): frame-style(styles.thmbox)

  doc
}